package com.koron.order.experiment.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.experiment.bean.dto.ExperimentDetailDto;
import com.koron.order.experiment.bean.query.ExperimentQuery;
import com.koron.order.experiment.bean.vo.ExperimentDetailVo;
import com.koron.order.experiment.bean.vo.ExperimentVo;
import com.koron.order.experiment.bean.vo.ReviewVo;
import com.koron.order.experiment.service.ExperimentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * (Experiment)表控制层
 * 草稿及列表
 *
 * @author zhouj
 * @since 2021-10-08 16:25:06
 */
@Api(tags = "试验工单表")
@RestController
@RequestMapping("/experiment/")
public class ExperimentController {

    @Autowired
    private ExperimentService experimentService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "新增或修改")
    @PostMapping("insertOrUpdate")
    public Response<String> insertOrUpdate(@RequestBody ExperimentDetailDto dto) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), experimentService, "insertOrUpdateDetail", String.class, dto));
    }

    @ApiOperation(value = "根据id删除")
    @DeleteMapping("deleteById")
    public Response<Integer> deleteById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), experimentService, "deleteById", Integer.class, id));
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping("queryById")
    public Response<ExperimentDetailVo> queryById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), experimentService, "queryById", ExperimentDetailVo.class, id));
    }

    @ApiOperation(value = "分页查询列表")
    @GetMapping("queryPageList")
    public Response<PageInfo<ExperimentVo>> queryPageList(ExperimentQuery query, PageQuery pageQuery) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), experimentService, "queryPageList", PageInfo.class, query, pageQuery));
    }

    @ApiOperation(value = "根据工单id查询审批信息")
    @GetMapping("queryReviewInfoByOrderId")
    public Response<ReviewVo> queryReviewInfoByOrderId(String orderId) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), experimentService, "queryReviewInfoByOrderId", ReviewVo.class, orderId));
    }

    @ApiOperation(value = "提交")
    @GetMapping("submitExperiment")
    public Response<Integer> submitExperiment(String orderId, String status) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), experimentService, "submitExperiment", Integer.class, orderId, status, null));
    }

}
